package com.anjubao.parking.municipal.parkinglot.controller;


import com.anjubao.parking.municipal.common.dto.ApiResult;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingTrendFailuresDto;
import com.anjubao.parking.municipal.parkinglot.service.ParkingTrendFailuresService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 区域运维事件统计API
 * @author anjubao
 */
@RestController
@RequestMapping("/parking-trend-failures-records")
@Api(value = "ParkingTrendFailuresController",tags = {"告警事件统计api"})
public class ParkingTrendFailuresController {

    @Autowired
    private ParkingTrendFailuresService parkingTrendFailuresService;
    private static final Logger logger = LoggerFactory.getLogger(ParkingStatFailuresController.class);

    /**
     * 最近30天运维事件趋势
     * @param cityId
     * @return
     */
    @GetMapping("")
    @ApiOperation(value = "统计最近30天运维事件趋势",notes = "最近30天所有设备故障数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityId", value = "所属城市",dataType ="int")
    })
    @ApiResponses(value = {
            @ApiResponse(code = 5000,message = "操作失败")
    })
    public ApiResult<List<ParkingTrendFailuresDto>> getTrendFailures(Integer cityId) {
        logger.info("最近30天统计所有设备运维事件占比 {} ",cityId);
        List<ParkingTrendFailuresDto> trendFailuresDtoList=parkingTrendFailuresService.getTrendFailures(cityId);
        return ApiResult.success(trendFailuresDtoList,trendFailuresDtoList.size());
    }


    @GetMapping("total")
    @ApiOperation(value = "告警列表数量")
    @ApiResponses(value = {
            @ApiResponse(code = 5000,message = "操作失败")
    })
    /**
     * 查询
     *
     * @return
     */
    public ApiResult<String> getWarningListTotal() {
        Long amount=parkingTrendFailuresService.getWarningListTotal();
        return ApiResult.success(String.valueOf(amount));
    }

}
